package com.gzl.gg.interceptor;

import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * Created by Administrator on 2018/10/30.
 */
public class MyWebRequestInterceptor implements WebRequestInterceptor {

    @Override
    public void preHandle(WebRequest webRequest) throws Exception {
        System.out.println("攔截器 a1");
//        System.out.println(" request session id : "+webRequest.getParameterMap());

        Set entrySet = webRequest.getParameterMap().entrySet();
        if (entrySet.size() != 0){
            Iterator it =  entrySet.iterator();
            while (it.hasNext()){
                Map.Entry entry = (Map.Entry) it.next();
                Object key = entry.getKey();
                Object value = entry.getValue();
                System.out.println(key + "-" + value);
            }
        }else{
            System.out.println("nulllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll");
        }
    }

    @Override
    public void postHandle(WebRequest webRequest, ModelMap modelMap) throws Exception {
        System.out.println("攔截器 a2");
    }

    @Override
    public void afterCompletion(WebRequest webRequest, Exception e) throws Exception {
        System.out.println("攔截器 a3");
    }
}
